package com.egao.common.module.company.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.egao.common.module.company.constants.PreachConstants;
import com.egao.common.module.company.mapper.AttachmentMapper;
import com.egao.common.module.company.entity.Attachment;
import com.egao.common.module.company.service.AttachmentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 附件表(Attachment)表服务实现类
 *
 * @author dl
 * @since 2021-02-22 09:07:15
 */
@Service("attachmentService")
public class AttachmentServiceImpl extends ServiceImpl<AttachmentMapper, Attachment> implements AttachmentService {

    @Override
    public void deleteAttach(Integer businessId, Integer businessType) {
        QueryWrapper<Attachment> queryWrapper = new QueryWrapper();
        queryWrapper.eq("business_id", businessId).eq("type", businessType);
        baseMapper.delete(queryWrapper);
    }

    @Override
    public List<Attachment> getAttachByBusinessId(Integer businessId, Integer businessType) {
        return baseMapper.selectList(new QueryWrapper<Attachment>().eq("business_id", businessId).eq("type", businessType));
    }

    @Override
    public void saveAttach(List<Attachment> attachments, Integer businessId, Integer businessType) {
        if (attachments != null && attachments.size() > 0) {
            for(Attachment attachment : attachments) {
                attachment.setBusinessId(businessId);
                attachment.setType(businessType);
            }
            saveBatch(attachments);
        }
    }
}